package cn.gaozhong.system.controller;


import cn.gaozhong.basic.util.AjaxResult;
import cn.gaozhong.basic.util.PageList;
import cn.gaozhong.system.domain.SystemDictionaryDetail;
import cn.gaozhong.system.query.SystemDictionaryDetailQuery;
import cn.gaozhong.system.service.ISystemDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sdd")
public class SystemDictionaryDetailController {
    @Autowired
    private ISystemDictionaryDetailService systemDictionaryDetailService;

    @GetMapping("/{id}")
    public SystemDictionaryDetail queryById(@PathVariable("id") Long id){
        return systemDictionaryDetailService.queryById(id);
    }
    @GetMapping("/{types_id}")
    public List<SystemDictionaryDetail> queryById(@PathVariable("types_id") Integer id){
        return systemDictionaryDetailService.loadByTypeId(id);
    }

    @GetMapping
    public List<SystemDictionaryDetail> queryAll(){
        return systemDictionaryDetailService.queryAll();
    }
    @PostMapping
    public PageList<SystemDictionaryDetail> queryPage(@RequestBody SystemDictionaryDetailQuery query){
        return systemDictionaryDetailService.queryPage(query);
    }
    @PutMapping
    public AjaxResult addOrUpd(@RequestBody SystemDictionaryDetail systemDictionaryDetail){
        try {
            if (systemDictionaryDetail.getId()==null){
                systemDictionaryDetailService.save(systemDictionaryDetail);
            } else {
                systemDictionaryDetailService.update(systemDictionaryDetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            systemDictionaryDetailService.removeById(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
    @PatchMapping
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
            systemDictionaryDetailService.patchRemove(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
}
